package com.mobi.cacti.ns.view;

import java.util.ArrayList;

import org.holoeverywhere.LayoutInflater;
import org.holoeverywhere.app.Fragment;
import org.holoeverywhere.widget.ListView;

import com.mobi.cacti.R;
import com.mobi.cacti.ns.model.ListItem;
import com.mobi.cacti.ns.view.adapter.ItemListAdapter;
import com.mobi.cacti.ns.view.tab.BaseContainerFragment;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;

public class NewsActivity extends Fragment {
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		View v = LayoutInflater.from(getActivity()).inflate(
				R.layout.news_layout, null);
		
		ArrayList<ListItem> items = new ArrayList<ListItem>();

		ListItem item = new ListItem();
		item.label = "News";
		item.ticketCountLabel = null;
		item.isShowRightArrow = true;
		items.add(item);
		
		item = new ListItem();
		item.label = "Promotions";
		item.ticketCountLabel = null;
		item.isShowRightArrow = true;
		items.add(item);
		
		ItemListAdapter adapter = new ItemListAdapter(getSupportActivity(), R.layout.rowitem_layout, items);
		ListView listView = (ListView) v.findViewById(R.id.rsslist);
		listView.setAdapter(adapter);
		
		listView.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position,
					long id) {
				Bundle bundle = new Bundle();
				
				if (position == 0) {
					// News
					bundle.putString("rss_type", "news");
				} else if (position == 1) {
					// Promotions
					bundle.putString("rss_type", "promotions");
				}
				
				NewsPromotionsListActivity newsPromotionsListActivity = new NewsPromotionsListActivity();
				newsPromotionsListActivity.setArguments(bundle);
				
				((BaseContainerFragment)getParentFragment()).replaceFragment(newsPromotionsListActivity, true);
			}
		});
		
		return v;
	}
}
